﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Service.Core.EfCoreRepository.Implements;
using Service.Core.EfCoreRepository.Interfaces;
using Service.Framework;
using Service.Framework.ApplicationEventBus;
using Service.Framework.AppStartup;
using Service.Framework.OperationLog;
using Service.Framework.SmsRecordLog;
using Service.Framework.Utils;
using Service.Framework.Utils.Helper;
using System.Reflection;
using System.Text;

namespace Service.Core.EfCoreRepository;

/// <summary>
/// 
/// </summary>
public class CoreRepositoryStartup : StartupModule<CoreRepositoryStartup>
{
    public override int Order { get; set; } = 40;
    /// <summary>
    /// 
    /// </summary>
    /// <param name="webApplicationBuilder"></param>
    public override void ConfigureServices(WebApplicationBuilder webApplicationBuilder)
    {


        var services = webApplicationBuilder.Services;
        services.AddDbContext<AppDbContextBase>(options =>
        {
            options.UseMySql("",
                new MySqlServerVersion(new Version(8, 0, 34)));
            options.UseLoggerFactory(null).EnableSensitiveDataLogging().EnableDetailedErrors();
        });
        services.AddScoped(typeof(IRepository<>), typeof(RepositoryBase<,>));
        services.AddScoped(typeof(IRepository<,>), typeof(RepositoryBase<,,>));
        services.AddScoped<IUnitOfWork>(p => p.GetRequiredService<AppDbContextBase>());
        services.AddScoped<ITransactionUnitOfWork>(p => p.GetRequiredService<AppDbContextBase>());
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="webApplication"></param>
    public override void Configure(WebApplication webApplication)
    {
        // Method intentionally left empty.
    }
}